package servlet;

import java.io.IOException; 
import javax.servlet.*; 
import javax.servlet.http.* ;
import business.LoginBusiness; 
//import business.LoginBusiness;
public class LoginServlet extends HttpServlet {
	public void init () throws ServletException {
		}

	public void doPost (HttpServletRequest request, HttpServletResponse response)
			throws ServletException,IOException { 
			doGet (request, response);
		}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter ("password"); 
		LoginBusiness lb = new LoginBusiness();
		String str = lb.login (username, password);
		HttpSession session = request.getSession(); 
		session.setAttribute ("state",str); 
		request.getSession().setAttribute("username", username); 
		if (str.equals("1"))
			response.sendRedirect (request.getContextPath()+"/adminmain.jsp");
		
		else if(str.equals("2"))
					response. sendRedirect (request.getContextPath() +"/main.jsp");
			//System.out.println(str);
		else 
			response. sendRedirect (request.getContextPath() +"/index.jsp");
	}	
}